package com.milkshopbackend.milkshop.Service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.milkshopbackend.milkshop.Service.ProductStatsService;
import com.milkshopbackend.milkshop.Service.ReviewService;
import com.milkshopbackend.milkshop.entity.Review;
import com.milkshopbackend.milkshop.mapper.ReviewMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class ReviewServiceImpl extends ServiceImpl<ReviewMapper, Review> implements ReviewService {

    private final ProductStatsService productStatsService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createReview(Review review) {
        // 保存评价
        save(review);
        
        // 更新商品统计
        productStatsService.updateProductStatsByOrder(review.getOrderId());
    }
} 